<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>JS Unit test for namespace icodeon.xml</title>
    <!--  script language="Javascript" src="../jsunit/app/jsUnitCore.js"></script-->
	<script language="Javascript" src="../icodeon.xml.js"></script>
	<script language="Javascript" src="../icodeon.cocd.js"></script>
	<script language="Javascript" src="../icodeon.rte.js"></script>
    <script language="Javascript"  src="./icodeon.jsunit.js"></script>

    <script language="Javascript">

        function testXmlMethods(){
        	try{
				var obj_DomDocument = icodeon.xml.createDomDocument("cocd");
           		assertNotNull("icodeon.xml.createDomDocument(root)", obj_DomDocument);
           		var obj_RootElement = obj_DomDocument.documentElement;
           		assertNotNull("documentElement", obj_RootElement);
           		
				obj_DomDocument = icodeon.xml.createDomDocument("cocd","http://ltsc.ieee.org/xsd/1484_11_3");
           		assertNotNull("icodeon.xml.createDomDocument(root, namespace)", obj_DomDocument);
           		obj_RootElement = obj_DomDocument.documentElement;
           		assertNotNull("documentElement", obj_RootElement);

           		assertEquals("obj_RootElement.nodeName", "cocd", obj_RootElement.nodeName);
           		assertEquals("obj_RootElement.nodeType", 1, obj_RootElement.nodeType);
           		
           		icodeon.xml.appendChildElement(obj_RootElement,"commentsFromLearner");
           		assertEquals("obj_RootElement.childNodes.length", 1, obj_RootElement.childNodes.length);
           		
           		icodeon.xml.appendChildElement(obj_RootElement,"commentsFromLMS");
           		assertEquals("obj_RootElement.childNodes.length", 2, obj_RootElement.childNodes.length);
           		
           		var obj_Serializer = new icodeon.xml.Serializer();
           		assertNotNull("icodeon.xml.serialize(obj_RootElement)", obj_Serializer.serialize(obj_RootElement));
           		
           	}
           	catch(obj_Error){
           		fail(obj_Error.message);
           	}
        }
        
        function testXPathMethods(){
        	try{

				var obj_DomDocument = icodeon.xml.createDomDocument("cocd","http://ltsc.ieee.org/xsd/1484_11_3");
           		obj_RootElement = obj_DomDocument.documentElement;
           		icodeon.xml.appendChildElement(obj_RootElement,"commentsFromLearner");
           		icodeon.xml.appendChildElement(obj_RootElement,"commentsFromLMS");
           		icodeon.xml.appendChildElement(obj_RootElement,"exit", "resume");
           		icodeon.xml.appendChildElement(obj_RootElement,"completionStatus", "incomplete");
           		
           		var arr_NameSpaces = new Array();
           		arr_NameSpaces[""] = "http://ltsc.ieee.org/xsd/1484_11_3";
           		
           		if(document.createExpression){
					var fn = function(str_Prefix){return arr_NameSpaces[str_Prefix];}
					var obj_Node = obj_RootElement;
					var obj_DomDocument = undefined;
					if(obj_Node.nodeType == 9){
						obj_DomDocument = obj_Node;
					}
					else{
						obj_DomDocument = obj_Node.ownerDocument;
					}

					var obj_XPathExpression = obj_DomDocument.createExpression("exit", fn);
					var obj_XPathResult = obj_XPathExpression.evaluate(obj_Node, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

           		}
           		else{
           			var str_NameSpaces = "";
					for(var str_Prefix in arr_NameSpaces){
						if(str_NameSpaces){
							str_NameSpaces += " ";
						}
						
						var str_Delim = "";
						if(str_Prefix.length > 0){
							str_Delim = ":";
						}

						
						str_NameSpaces += "xmlns" + str_Prefix + str_Delim + "='" + arr_NameSpaces[str_Prefix] + "'";
					}
					
					var obj_Node = obj_RootElement;
					var obj_DomDocument = undefined;
					if(obj_Node.nodeType == 9){
						obj_DomDocument = obj_Node;
					}
					else{
						obj_DomDocument = obj_Node.ownerDocument;
					}

					obj_DomDocument.setProperty("SelectionLanguage","XPath");
					obj_DomDocument.setProperty("SelectionNamespaces", str_NameSpaces);
					if(obj_Node.nodeType == 9){
						obj_Node = obj_Node.documentElement;
					}
					var singleNode = obj_Node.selectSingleNode("exit");
					//alert(singleNode.nodeName);

           		}
           		
           		var obj_Expr = new icodeon.xml.XPathExpression("exit", arr_NameSpaces);
           		var singleNode = obj_Expr.getNode(obj_Node);
				assertEquals("obj_Expr.getNode(obj_Node)", "exit", singleNode.nodeName);

           		
				
           	}
           	catch(obj_Error){
           		fail(obj_Error.message);
           	}
        }
    </script>
</head>
<body>
<h2>JS Unit Tests for Namespace: icodeon.xml</h2>
<form>
<input type="button" onclick="testXmlMethods();" value="testXmlMethods" />&nbsp;
<input type="button" onclick="testXPathMethods();" value="testXPathMethods" />&nbsp;
</form>
<div id="testLog"></div>
</body>
</html>
